<?php 
    include("includes/connect_db.php");

    $host = $_POST['host'];

    $sql_lihat_host = "SELECT * FROM tb_host WHERE id_host = '$host'";
    $query_lihat_host = mysql_query($sql_lihat_host);
    $lihat_host = mysql_fetch_array($query_lihat_host);
    
    $koneksiBaru = mysql_connect($lihat_host['host'], $lihat_host['username'], $lihat_host['password']) or die("Connection Error: " . mysql_error());

    mysql_select_db($lihat_host['db'], $koneksiBaru) or die("Error conecting to db.");
?>

<div>
    <div class="parameterFungsi border" style="padding: 0px;">
        <table class="table table-bordered">
            <?php
                $sql_lihat_fungsi = "SHOW FUNCTION STATUS";
                $query_lihat_fungsi = mysql_query($sql_lihat_fungsi, $koneksiBaru);
                $lihat_fungsi = mysql_fetch_array($query_lihat_fungsi);

                $sql_parameterFungsi = "SELECT CAST(param_list AS CHAR(1000) CHARACTER SET utf8) AS parameter FROM mysql.proc WHERE db = '$lihat_host[db]' AND NAME = '$lihat_fungsi[1]'";
                $query_parameterFungsi = mysql_query($sql_parameterFungsi);
                $parameterFungsi = mysql_fetch_array($query_parameterFungsi);

                if ($parameterFungsi == '') {
                } else {
                    $rincianParameterFungsi = explode(',', $parameterFungsi[0]);
                    $jum = count($rincianParameterFungsi);
                    $x = 0;
                    foreach ($rincianParameterFungsi as $parParameterFungsi) {
                        $temp = ltrim($parParameterFungsi);
                        $lihatParameterFungsi = explode(" ", $temp);
            ?>
            <tr>
                <td class="namaParameterFungsiAwal" data-index="<?php echo $x; ?>">
                    <span><?php echo $lihatParameterFungsi[0]; ?></span>
                </td>
                <td>
                    <input class="namaParameterFungsi" type="text" placeholder="Masukkan Nama Parameter">
                </td>
            </tr>
            <?php
                    $x++;
                    }
                }
            ?>
        </table>
    </div>
</div>
<div class="footer">
    <button class="btn btn-info btnParameterFungsi" disabled="disabled">Simpan</button>
</div>
